package com.sunyard.domee.controller.convert;

import com.google.common.collect.Lists;
import com.sunyard.domee.common.enums.CouponTypeEnum;
import com.sunyard.domee.controller.vo.MarketingCouponVO;
import com.sunyard.domee.service.bo.MarketingCouponBO;
import org.apache.commons.collections.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * 优惠券
 * 
 * @author xw
 * @email wei.xiao  çæææ
 * @date 2020-07-02 22:52:45
 */
public class MarketingCouponConvert {

	public static MarketingCouponBO toBO(MarketingCouponVO marketingCouponVO) {
		if (marketingCouponVO == null) {
			return null;
		}
		MarketingCouponBO marketingCouponBO = new MarketingCouponBO();
		marketingCouponBO.setId(marketingCouponVO.getId());
		marketingCouponBO.setCouponName(marketingCouponVO.getCouponName());
		marketingCouponBO.setCouponType(marketingCouponVO.getCouponType());
		marketingCouponBO.setDiscountMax(marketingCouponVO.getDiscountMax());
		marketingCouponBO.setAmountFullMax(marketingCouponVO.getAmountFullMax());
		marketingCouponBO.setDiscount(marketingCouponVO.getDiscount());
		marketingCouponBO.setLimitNum(marketingCouponVO.getLimitNum());
		marketingCouponBO.setEffectiveDate(marketingCouponVO.getEffectiveDate());
		marketingCouponBO.setEffectiveStartDate(marketingCouponVO.getEffectiveStartDate());
		marketingCouponBO.setEffectiveEndDate(marketingCouponVO.getEffectiveEndDate());
		marketingCouponBO.setCouponStatus(marketingCouponVO.getCouponStatus());
		marketingCouponBO.setCreaterCode(marketingCouponVO.getCreaterCode());
		marketingCouponBO.setUpdateTime(marketingCouponVO.getUpdateTime());
		marketingCouponBO.setCreateTime(marketingCouponVO.getCreateTime());
		marketingCouponBO.setUpdateCode(marketingCouponVO.getUpdateCode());
		marketingCouponBO.setDelFlag(marketingCouponVO.getDelFlag());
		return marketingCouponBO;
	}

	public static MarketingCouponVO toVO(MarketingCouponBO marketingCouponBO) {
		if (marketingCouponBO == null) {
			return null;
		}
		MarketingCouponVO marketingCouponVO = new MarketingCouponVO();
		marketingCouponVO.setId(marketingCouponBO.getId());
		marketingCouponVO.setCouponName(marketingCouponBO.getCouponName());
		marketingCouponVO.setCouponType(marketingCouponBO.getCouponType());
		marketingCouponVO.setDiscountMax(marketingCouponBO.getDiscountMax());
		marketingCouponVO.setAmountFullMax(marketingCouponBO.getAmountFullMax());
		marketingCouponVO.setDiscount(marketingCouponBO.getDiscount());
		marketingCouponVO.setLimitNum(marketingCouponBO.getLimitNum());
		marketingCouponVO.setEffectiveDate(marketingCouponBO.getEffectiveDate());
		marketingCouponVO.setEffectiveStartDate(marketingCouponBO.getEffectiveStartDate());
		marketingCouponVO.setEffectiveEndDate(marketingCouponBO.getEffectiveEndDate());
		marketingCouponVO.setCouponStatus(marketingCouponBO.getCouponStatus());
		marketingCouponVO.setCreaterCode(marketingCouponBO.getCreaterCode());
		marketingCouponVO.setUpdateTime(marketingCouponBO.getUpdateTime());
		marketingCouponVO.setCreateTime(marketingCouponBO.getCreateTime());
		marketingCouponVO.setUpdateCode(marketingCouponBO.getUpdateCode());
		marketingCouponVO.setDelFlag(marketingCouponBO.getDelFlag());
		//优惠规则
		if(CouponTypeEnum.OVER.getCode().equals(marketingCouponBO.getCouponType())){
			//满减券
			StringBuffer sb = new StringBuffer();
			String discountDesc = sb.append("满" + marketingCouponBO.getAmountFullMax())
					.append("减").append(marketingCouponBO.getDiscount())
					.append(",最高减").append(marketingCouponBO.getDiscountMax()).append("元")
					.toString();
			marketingCouponVO.setDiscountDesc(discountDesc);
		}
		if(CouponTypeEnum.CASH.getCode().equals(marketingCouponBO.getCouponType())){
			//现金券
			StringBuffer sb = new StringBuffer();
			String discountDesc = sb.append("满" + marketingCouponBO.getAmountFullMax())
					.append("抵扣").append(marketingCouponBO.getDiscount())
					.toString();
			marketingCouponVO.setDiscountDesc(discountDesc);
		}
		if(CouponTypeEnum.DISCOUNT.getCode().equals(marketingCouponBO.getCouponType())){
			//打折券
			StringBuffer sb = new StringBuffer();
			String discountDesc = sb.append("满" + marketingCouponBO.getAmountFullMax())
					.append("打").append(marketingCouponBO.getDiscount()/10D)
					.append("折").append("最高减")
					.append(marketingCouponBO.getDiscountMax()).append("元")
					.toString();
			marketingCouponVO.setDiscountDesc(discountDesc);
		}
		return marketingCouponVO;
	}

	public static List<MarketingCouponBO> toBOList(List<MarketingCouponVO> voList) {
        if (CollectionUtils.isEmpty(voList)) {
			return Collections.emptyList();
		}

		List<MarketingCouponBO> boList = Lists.newArrayList();
		for (MarketingCouponVO marketingCouponVO : voList) {
			if (marketingCouponVO != null) {
				boList.add(toBO(marketingCouponVO));
			}
		}
		return boList;
	}

	public static List<MarketingCouponVO> toVOList(List<MarketingCouponBO> boList) {
        if (CollectionUtils.isEmpty(boList)) {
			return Collections.emptyList();
		}

		List<MarketingCouponVO> voList = Lists.newArrayList();
		for (MarketingCouponBO marketingCouponBO : boList) {
			if (marketingCouponBO != null) {
				voList.add(toVO(marketingCouponBO));
			}
		}
		return voList;
	}

}
